package com.augurit.gzcgwsp.rqqyjyxk.qx.web;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.jbpm.api.ProcessEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.BaseAction;
import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.syscode.service.ISysCodeService;
import com.augurit.common.syscode.web.form.SysCodeForm;
import com.augurit.common.system.util.WebContextUtils;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.ReflectionUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkCyryzkdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkPzrqgyzdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkQysbclmc;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszrypbqk;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqjszzysb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqqxdylb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqqxsbylb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqqxssdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRqssdjb;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkRypbqk;
import com.augurit.gzcgwsp.excelimportexport.entity.YwRqQyjyxkZyaqjsglryzk;
import com.augurit.gzcgwsp.printDoc.service.IYwPrintDocService;
import com.augurit.gzcgwsp.printDoc.web.form.YwPrintDocForm;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxk;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalCyryzkdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalPzrqgyzdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalQysbclmc;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszrypbqk;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqjszzysb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqqxdylb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqqxsbylb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqqxssdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRqssdjb;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalRypbqk;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxkFinalZyaqjsglryzk;
import com.augurit.gzcgwsp.rqqyjyxk.qx.service.IYwRqQyjyxkQxService;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkForm;
import com.augurit.gzcgwsp.sendNotice.service.IYwWebserviceInfoService;
import com.augurit.gzcgwsp.ssylb.entity.YwRqRqssylb;
import com.augurit.gzcgwsp.wfex.app.doc.IOaDocCodeServiceEX;
import com.augurit.gzcgwsp.wfex.bi.service.IWfBusTemplateServiceEX;
import com.augurit.gzcgwsp.wfex.bi.service.IWfTemplateAttachmentRefServiceEX;
import com.augurit.gzcgwsp.wfex.bi.web.form.WfTemplateAttachmentRefFormEX;
import com.augurit.gzcgwsp.wfex.common.service.IWfServiceEX;
import com.augurit.gzcgwsp.wfex.common.util.WfUtilsEX;
import com.augurit.gzcgwsp.ywcmn.entity.YwComFinalQyxx;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.wf.bi.service.IWfBusTemplateService;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.bi.web.form.WfBusTemplateForm;
import com.augurit.wf.common.constant.WfConstant;
import com.augurit.wf.common.entity.Jbpm4HistTask;
import com.augurit.wf.common.form.WfBusSaveResult;
import com.augurit.wf.common.service.IWfBusClientService;
import com.augurit.wf.common.service.IWfService;
import com.augurit.wf.common.util.WfUtils;
import com.augurit.wf.common.web.WfBusClientAction;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-rq-qyjyxkpz-qx.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxkgd.jsp"),
	@Result(name = WfConstant.PRINT, location = WfConstant.PRINT_JSP),
	@Result(name = CrudActionSupport.INPUT, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/qx/YwRqQyjyxkgdQx-input.jsp"),
	@Result(name = WfConstant.PRINT_DIR, location = WfConstant.PRINT_DIR_JSP),
	@Result(name = WfConstant.MAKE_DOCUMENT, location = "/gzcgwsp/wfex/client/common/qumake-noline-document.jsp"),
	@Result(name = YwRqQyjyxkgdQxAction.UPLOAD_SQB, location = "/gzcgwsp/wfex/client/common/upload_sqb.jsp"),
	@Result(name = "showview", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/qx/YwRqQyjyxkgd-view.jsp")
})
public class YwRqQyjyxkgdQxAction extends WfBusClientAction<YwRqQyjyxkForm>{
	private final static Logger log=Logger.getLogger(YwRqQyjyxkgdQxAction.class);
	public static final String UPLOAD_SQB = "upload_sqb";	
	private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private IWfService wfService;
    @Autowired
    private IYwComQyxxService qyxxService;
	@Autowired
	private IYwRqQyjyxkQxService ywRqQyjyxkQxService;
    @Autowired
    private ISysCodeService syscodeService;
    @Autowired
    private ProcessEngine processEngine;
    @Autowired
    private IWfBusTemplateService wfBusTemplateService;    
    @Autowired
    private IWfTemplateAttachmentRefServiceEX wfTemplateAttachmentRefServiceEX;
    @Autowired
	private IYwPrintDocService ywPrintDocService;    
    @Autowired
    private IWfServiceEX wfServiceEX;    
    @Autowired
    private IWfBusTemplateServiceEX wfBusTemplateServiceEX;
    @Autowired
	private IYwWebserviceInfoService ywWebserviceInfoService;    
    @Autowired
    private IOaDocCodeServiceEX oaDocCodeServiceEX;
    
	private YwRqQyjyxkForm form;
	private Long id;
	private Long[] checkedIds;
	private Page<YwRqQyjyxkForm> page = new Page<YwRqQyjyxkForm>(10);
	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		ywRqQyjyxkQxService.search(page, form);
		return SUCCESS;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
         setOpinions();
        getRequest().setAttribute("CurrUserName", this.getLoginUser().getUser().getUserName());
        List<SysCodeForm> sqdwlx = syscodeService.getItems("YW_SQDW_LX");
        List<SysCodeForm> ywHbbm = syscodeService.getItems("ALL_HBBM");
        getRequest().setAttribute("sqdwlx", sqdwlx);
        getRequest().setAttribute("ywhbbm", ywHbbm);
		return INPUT;
	}
	

	
	/**
     * 保存业务并关联流程实例
     */
    public String wfBusSave() {
    	try {
        	//修改每次提交新增申请号码，比如表单提交的受理号是gz26120320XXXXX，但另外的acceptNo2是120327000636
        	if(StringUtils.isNotBlank(form.getAcceptNo()) && form.getAcceptNo().indexOf("XXXX")>0){
        		if(StringUtils.isNotBlank(form.getAcceptNo2()) && form.getAcceptNo2().indexOf("XXXX")<0){
        			form.setAcceptNo(form.getAcceptNo2());
        		}
        	}	
        if (form.getQyid() == null) {
            YwComQyxxForm qyxxForm = qyxxService.getFormBySqdw(form.getSqdw(),form.getTemplateCode());
            if (qyxxForm != null) {
                WfUtils.renderWfFailtureJson("该企业名称已经存在，请点击选择企业从企业列表中选择该企业！");
                return null;
            }
        }
    	String isYsl = super.getParameter("isYsl");
    	LoginUserForm user = (LoginUserForm)getSession().getAttribute(WebContextUtils.SES_LOGIN_USER);
        String orgName = user.getOrg().getOrgName();
		if(StringUtils.isNotBlank(orgName)){//把所属区保存到WfBusInstance表的busMemo2字段里面
			form.setSsq(orgName.substring(0,3));	
		}
        WfBusInstanceTaskForm task = this.wfBusSave((IWfBusClientService)ywRqQyjyxkQxService, form, YwRqQyjyxk.class.getSimpleName());
        String durationExpression = wfServiceEX.getProcDueExpressIonByTaskInstDbid(task.getTaskInstDbid());
        if (form.getDfsj() == null) {
            Date dfsj = wfServiceEX.calculateDueDate(form.getLarq(), durationExpression);
            form.setDfsj(dfsj);
            this.save();
        }
        
        if (StringUtils.isNotBlank(isYsl) && "1".equals(isYsl)) {
        	String executionId =  processEngine.getHistoryService().createHistoryTaskQuery().taskId(task.getTaskInstDbid().toString()).uniqueResult().getExecutionId();
            processEngine.getExecutionService().jumpToActivity(executionId, "cksa");
            form.setYsl(null);
            ywRqQyjyxkQxService.changeYslState(form.getId(), 2l,null);
        }
        WfUtils.renderWfBusSaveJson(task, form);
		} catch (Exception e) {
			e.printStackTrace();
			WfUtils.renderWfFailtureJson("请检查输入内容长度是否过大!");
		}
        return null;
    }
    
    /**
     * 预受理
     * @return
     * @throws Exception
     */
    public String wfBusYslTuih() throws Exception {
    	try {
    		ywRqQyjyxkQxService.wfBusYslTuih(form, this.getLoginUser());
			WfBusSaveResult result = new WfBusSaveResult(true, null);
			result.setTask(new WfBusInstanceTaskForm());
			Struts2Utils.renderJson(result);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
        return null;
    }
	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		ywRqQyjyxkQxService.save(form);
		return RELOAD;
	}

	/**
	 * 删除一条记录
	 */
	@Override
	public String delete() throws Exception {
		ywRqQyjyxkQxService.delete(id);
		return RELOAD;
	}
	
	/**
     * 制文
     * @return
     * @throws Exception
     */
    public String makeDocument() throws Exception {
        if (StringUtils.isNotBlank(form.getRedHeadFileId())) {
            String redHeadFilePath = wfBusTemplateServiceEX.getPrintTemplatePath(Long.parseLong(form.getRedHeadFileId()));
            form.setRedHeadFilePath(redHeadFilePath);
        }
         //加载收件通知书里面的附件
		 String isred=getRequest().getParameter("isred");
		 //如果不要打印红头
		 if("no".equals(isred)){
//			 String redHeadFilePath = wfBusTemplateServiceEX.getRedFile(form.getTemplateCode());
		 	form.setRedHeadFilePath("");
		 }
		 String templateCode = getTemplateCode();
		 if(templateCode != null && templateCode.trim().length() > 0){
         	String printTemplatePath = wfBusTemplateServiceEX.getPrintTemplatePath(templateCode, WfTemplateAttachmentRefFormEX.ZHENGWEN_TEMPLATE_TYPE);
            form.setTemplatePath(printTemplatePath);
            WfTemplateAttachmentRefFormEX wfTemplateAttachmentRefFormEX = (WfTemplateAttachmentRefFormEX)wfTemplateAttachmentRefServiceEX.get(Long.parseLong(form.getZhengwenFileId()));
            String zhengwenPath = wfTemplateAttachmentRefFormEX.getFilePath() + "/" + wfTemplateAttachmentRefFormEX.getFileRealName();
            log.info("制文的模版路径---------》"+zhengwenPath);
            form.setZhengwenPath(zhengwenPath);
            form.setCurDate(DateUtilsEX.convertDate2Chinese(new Date()));
            form.setCurYear(String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
            Long seq=oaDocCodeServiceEX.getQuCurSeqAndAddSeq(templateCode, wfTemplateAttachmentRefFormEX.getFileCode(),
            		form.getId(),this.getLoginUser());
            if(seq.intValue()<10){
	        	form.setCurSeq("0"+String.valueOf(seq));
	        }else{
	        	form.setCurSeq(String.valueOf(seq));
	        }
            
            if("qubzsltzs".equals(wfTemplateAttachmentRefFormEX.getFileCode())){
            	List<YwPrintDocForm> ywPrintDocFormList = ywPrintDocService.get(form.getTemplateCode(),"qubzcltzs", form.getId());
                if(ywPrintDocFormList!=null&&ywPrintDocFormList.size()>0){
                	YwPrintDocForm ywPrintDocForm=ywPrintDocFormList.get(0);
                	form.setWh(ywPrintDocForm.getFileNum());
                	form.setWh2(ywPrintDocForm.getFileNum());
                }            	
            }
           
            WfBusTemplateForm wfBusTemplateForm = wfBusTemplateService.getByTemplateCode(getTemplateCode());
            if (wfBusTemplateForm != null) {
                form.setCbyw(wfBusTemplateForm.getTemplateName().replace("区县", "").replace("区", ""));
            }
 			form.setCbyw2(form.getCbyw());
 			form.setCbyw3(form.getCbyw());
 			form.setCbyw4(form.getCbyw());
            //---获取受理通知书时间---韩修改
            YwRqQyjyxkForm sltjsForm=new YwRqQyjyxkForm();
            sltjsForm.setFileCode("sltzs");
            List<YwPrintDocForm> ywPrintDocFormList = ywPrintDocService.get(form.getTemplateCode(),sltjsForm.getFileCode(), form.getId());
            if(ywPrintDocFormList!=null&&ywPrintDocFormList.size()>0){
            	YwPrintDocForm ywPrintDocForm=ywPrintDocFormList.get(0);
            	form.setSlDate(DateUtilsEX.convertCommonDate(ywPrintDocForm.getCreatDate()));
            }else{//受理通知书没有制作时加入
            	form.setSlDate(DateUtilsEX.convertCommonDate(form.getLarq()));
            }
            WfUtilsEX.wfBusPrint(form);
            getRequest().setAttribute("isunified", false);//是否全委统一
            BaseAction.getRequest().setAttribute("templateFilePath",zhengwenPath);
            BaseAction.getRequest().setAttribute("fileCode", wfTemplateAttachmentRefFormEX.getFileCode());
            BaseAction.getRequest().setAttribute("entityId", form.getId());
            BaseAction.getRequest().setAttribute("seq", form.getCurSeq());
            BaseAction.getRequest().setAttribute("templateId", wfTemplateAttachmentRefFormEX.getId());
//            BaseAction.getRequest().setAttribute("busType", OaFawen.class.getSimpleName());
        }
        return WfConstant.MAKE_DOCUMENT;
    }
    
    /**
     * 上传申请信息
     * @return
     * @throws Exception
     */
    public String uploadSqb() throws Exception {
        if (StringUtils.isNotBlank(form.getRedHeadFileId())) {
            String redHeadFilePath = wfBusTemplateServiceEX.getPrintTemplatePath(Long.parseLong(form.getRedHeadFileId()));
            form.setRedHeadFilePath(redHeadFilePath);
        }
        String templateCode = getTemplateCode();
        if(templateCode != null && templateCode.trim().length() > 0){
            String printTemplatePath = wfBusTemplateServiceEX.getPrintTemplatePath(templateCode, WfTemplateAttachmentRefFormEX.ZHENGWEN_TEMPLATE_TYPE);
            form.setTemplatePath(printTemplatePath);
            WfTemplateAttachmentRefFormEX wfTemplateAttachmentRefFormEX = (WfTemplateAttachmentRefFormEX)wfTemplateAttachmentRefServiceEX.get(Long.parseLong(form.getZhengwenFileId()));
            String zhengwenPath = wfTemplateAttachmentRefFormEX.getFilePath() + "/" + wfTemplateAttachmentRefFormEX.getFileRealName();
            form.setZhengwenPath(zhengwenPath);
            form.setCurDate(DateUtilsEX.convertDate2Chinese(new Date()));
            form.setCurYear(String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
            form.setCurSeq(String.valueOf(oaDocCodeServiceEX.getCurSeqAndAddSeq(templateCode, wfTemplateAttachmentRefFormEX.getFileCode(),form.getId())));
            WfUtils.wfBusPrint(form);
            
            BaseAction.getRequest().setAttribute("fileCode", wfTemplateAttachmentRefFormEX.getFileCode());
            BaseAction.getRequest().setAttribute("entityId", form.getId());
            BaseAction.getRequest().setAttribute("templateId", wfTemplateAttachmentRefFormEX.getId());
//            BaseAction.getRequest().setAttribute("busType", OaFawen.class.getSimpleName());
        }
        return WfConstant.MAKE_DOCUMENT;
    }
	
    /**
	 * 删除多条记录
	 */
	@Override
	public String deleteMore() throws Exception{
		ywRqQyjyxkQxService.delete(checkedIds);
		return RELOAD;
	}
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		LoginUserForm uform=(LoginUserForm)BaseAction.getRequest().getSession().getAttribute("SES_LOGIN_USER");
		String username=uform.getUser().getUserName();
		if(id != null){
			form = ywRqQyjyxkQxService.getJyxk(id,"pz");
		}
		else
			form = new YwRqQyjyxkForm();
		if(StringUtils.isNotBlank(form.getCbyw())){
			form.setCbyw(form.getCbyw().replace("区县", "").replace("区", ""));
		}
		form.setArea(uform.getOrg().getOrgName().substring(0,3));
		if (form.getSarq() == null) {
            form.setSarq(new Date());
        }
		if (StringUtils.isBlank(form.getAcceptNo())) {
			String rq = DateUtilsEX.getYearAndMonthAndDay();
        	form.setAcceptNo("gz26"+rq+"XXXXX");
        }
		if (StringUtils.isBlank(form.getCbyw())) {
            WfBusTemplateForm wfBusTemplateForm = wfBusTemplateService.getByTemplateCode(getTemplateCode());
            if (wfBusTemplateForm != null) {
                form.setCbyw(wfBusTemplateForm.getTemplateName().replace("区县", "").replace("区", ""));
            }
        }
		
		if (StringUtils.isBlank(form.getSjr())) {
            form.setSjr(this.getLoginUser().getUser().getUserName());
        }
		
		if (StringUtils.isBlank(form.getCbbm())) {
            form.setCbbm("燃气科");
        }
		
		if (StringUtils.isBlank(form.getJbrxm())) {
            form.setJbrxm(this.getLoginUser().getUser().getUserName());
            form.setJbrdh(this.getLoginUser().getUser().getOfficeTel());
            form.setJbrxm2(form.getJbrxm());
            form.setJbrdh2(form.getJbrdh());
        }
		if(form.getLarq() == null){
			Date newLarq = new Date();
			form.setLarq(newLarq);
	        form.setLarq2(newLarq);
		}
        
		form.setSajg(getLoginUser().getOrg().getOrgName());
        form.setSajg2(form.getSajg());
        form.setSajg3(form.getSajg());
        form.setSajg4(form.getSajg());
        form.setSajg5(form.getSajg());
        form.setSajg6(form.getSajg());
        form.setQu("("+uform.getOrg().getOrgName().substring(0, 1)+")");
		
		if(form.getId()!=null){
			List<YwRqRqssylb> ssylbs=ywRqQyjyxkQxService.findSsylbs(form.getId());
			getRequest().setAttribute("ssylbList", ssylbs);
		}
        try {
            if (form.getSarq() == null) {
                form.setSarq(new Date());
            }else{
            	form.setSqrq(form.getSarq());
                form.setSqrq2(DateUtils.dateTimeToString(form.getSarq(), DateUtils.YEAR_MOUTH_DAY_));
            }
            if (form.getCpsj() == null) {
                form.setCpsj(new Date());
            }
            if (form.getSqrq() == null) {
                form.setSqrq(new Date());
            }
            
            if(getTaskInstDbid() != null){
            	this.findJbrspUtil();	//获取审批过程中的意见列表
            	this.findCldspUtil();
            	this.findWldspUtil();
            	
            	this.cpbJbrspUtil();
            	this.cpbCldspUtil();
            	this.cpbWldspUtil();
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        
        //获取延期天数
    	int yqtsInt = wfServiceEX.getYqtsByProcInstId(super.getProcInstId());
    	form.setYqts(String.valueOf(yqtsInt));
    	
    	//补交告知原因
    	if(form.getBjgzyy()==null){
    		form.setBjgzyy(this.getOpinion("jbrcs"));
    	}
    	//补交告知时间
    	if(form.getBjgzsj()==null){
    		form.setBjgzsj(new Date());
    	}
    	//受理告知时间
//    	if(form.getBjslsj()==null){
//    		form.setBjslsj(new Date());
//    	}
//    	//补交告知发出人
//    	if(form.getBjgzfcr()==null){
//    		form.setBjgzfcr(username);
//    	}
//        //补交告知受理人
//    	if(form.getSldwcbrxm()==null){
//    		form.setSldwcbrxm(username);
//    		
//    	}
    	//补交告知受理地点
    	if(form.getBjsljtdd()==null){
    		form.setBjsljtdd(uform.getOrg().getOrgName());
    	}
     	//答复时间
    	if(id!=null && StringUtils.isNotBlank(this.getTemplateCode())){
    		Date date=this.wfServiceEX.getDfsjByTempleteCode(this.getTemplateCode(),id);
    		form.setDfsj(date);
    	}
    	
    	if(form.getShbShsj() == null){
    		form.setShbShsj(new Date());
    	}
    	if(form.getKhbShsj() == null){
    		form.setKhbShsj(new Date());
    	}
    	    	
    	String xkzPzsj = "";
		if(StringUtils.isNotBlank(form.getStartyear()) && StringUtils.isNotBlank(form.getStartmonth()) && StringUtils.isNotBlank(form.getStartday())){
			xkzPzsj = DateUtilsEX.ChineseYear2Number(form.getStartyear()) + "年" + DateUtilsEX.ChineseMonth2Number(form.getStartmonth()) + "月" + DateUtilsEX.ChineseDay2Number(form.getStartday()) + "日";
		}
		form.setXkzPzsj(xkzPzsj);

    	
	}
	
	//打印 呈批表经办人意见
	private void cpbJbrspUtil(){
		String names = "'jbrsl' , 'jbrsj'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer jbrspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			jbrspYj.append(list.get(i).getHandleComments()).append("\n")
			.append("    ").append(list.get(i).getAssigneeName()).append("\n")
			.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
			break; 
			}
		}
		form.setCpbJbryj(jbrspYj.toString());
	}
	//打印  呈批表 处领导意见
	private void cpbCldspUtil(){
		String names = "'cfgldsh' , 'czgldsh'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer cldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			cldspYj.append(list.get(i).getHandleComments()).append("\n")
			.append("    ").append(list.get(i).getAssigneeName()).append("\n")
			.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
			  break;
		   }
		}
		form.setCpbCldyj(cldspYj.toString());
	}
	//打印  呈批表 委领导意见
	private void cpbWldspUtil(){
		String names = "'wfgldsh' , 'wzgldsp'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer wldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			wldspYj.append(list.get(i).getHandleComments()).append("\n")
			.append("    ").append(list.get(i).getAssigneeName()).append("\n")
			.append(simpleDateFormat.format(list.get(i).getHandleCommentsTime())).append("\n");
			  break;
		   }
		}
		form.setCpbWldyj(wldspYj.toString());
	}
	/**
	 * from加载	经办人审批意见列表工具方法
	 */
	private void findJbrspUtil(){
		String names = "'jbrsl' , 'jbrsj'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer jbrspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
		  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
				jbrspYj.append(list.get(i).getHandleComments());
				form.setJbrslsj(list.get(i).getHandleCommentsTime());
				form.setJbrslxm(list.get(i).getAssigneeName());
				break;
			}
		}
		form.setJbrsl(jbrspYj.toString());
	}
	/**
	 * from加载	处领导审批意见列表工具方法
	 */
	private void findCldspUtil(){
		String names = "'cfgldsh' , 'czgldsh'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer cldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			cldspYj.append(list.get(i).getHandleComments());
			form.setCldspsj(list.get(i).getHandleCommentsTime());
			form.setCldspxm(list.get(i).getAssigneeName());
			break;
		  }
		}
		form.setCldsp(cldspYj.toString());
	}
	/**
	 * from加载	委领导审批意见列表工具方法
	 */
	private void findWldspUtil(){
		String names = "'wfgldsh' , 'wzgldsp'";
		List<Jbpm4HistTask> list = wfServiceEX.getHandleCommentsByTaskInstDbidAndActivityNames(getTaskInstDbid(),names);
		StringBuffer wldspYj = new StringBuffer();
		for(int i=list.size()-1;i>=0;i--){//只取一条记录
			  if(StringUtils.isNotBlank(list.get(i).getHandleComments())){
			wldspYj.append(list.get(i).getHandleComments());
			form.setWldspsj(list.get(i).getHandleCommentsTime());
			form.setWldspxm(list.get(i).getAssigneeName());
			 break;
	     }
		}
		form.setWldsp(wldspYj.toString());
	}
	
	/**
	 * 设施一览表保存
	 * @return
	 */
	public String upload() throws Exception{
//		HttpServletResponse response=ServletActionContext.getResponse();
//		response.setCharacterEncoding("utf-8");
//		
//		YwRqRqssylb ssylb=new YwRqRqssylb();
//		ssylb.setSsylbid(form.getSsylbid());
//		ssylb.setSsmc(form.getSsmc());
//		ssylb.setSslb(form.getSslb());
//		ssylb.setZdlb(form.getZdlb());
//		ssylb.setFzr(form.getFzr());
//		ssylb.setSsaddress(form.getSsaddress());
//		ssylb.setQyjyxkid(form.getId());
//		System.out.println(form.getZdlb()+"---------------");
//		
//		if(null!=form.getUpload()) {
//		InputStream is = new FileInputStream(form.getUpload());
////		   String root = ServletActionContext.getRequest().getRealPath(
////		     "/upload");
//		   String root = "/usr/local/tomcat/webapps/gzcgwsp/resources/AttacheFile/";
//		   SimpleDateFormat sdf=new SimpleDateFormat("yMMddHHmmss");
//		   
//		   String filepath=sdf.format(new Date())+"."+form.getUploadFileName().substring(form.getUploadFileName().lastIndexOf('.')+1);
//		  
//		   form.setUploadFileName(filepath);
//		   
//		   File destFile = new File(root, form.getUploadFileName());
//		 //linux上的路径/usr/local/tomcat/webapps/gzcgwsp/resources/AttacheFile/
//		   System.out.println(root+"/"+ form.getUploadFileName()+"----"+filepath);
//		   OutputStream os = new FileOutputStream(destFile);
//		   byte[] buffer = new byte[512];
//		   int length = 0;
//		   while ((length = is.read(buffer)) > 0)
//		   {
//		    os.write(buffer, 0, length);
//		   }
//		   is.close();
//		   os.close();
//		   ssylb.setFilepath("/resources/AttacheFile/"+filepath);
////		   ssylb.setFilepath(filepath);
//		}else{
//			YwRqRqssylb temp=ywRqQyjyxkQxService.getSsylb(form.getSsylbid());
//			ssylb.setFilepath(temp.getFilepath());
//		}
//		
		 return null;
	 }
	
	/**
	 * 根据案件Id查找设施一览表列表
	 * @return
	 * @throws Exception
	 */
	public String ssylblist()  throws Exception {
		String taskid=getRequest().getParameter("taskid");
		List<YwRqRqssylb> list=ywRqQyjyxkQxService.findSsylbs(form.getId());
		List<Map> maps=new ArrayList<Map>();
		
			for(YwRqRqssylb entity:list){
				if(StringUtils.isNotBlank(taskid)){
					Map<String,String> map=WfUtilsEX.buildMap(entity,"yyyy年MM月dd日");
					map.put("taskid", taskid);
					maps.add(map);
				}else{
					Map<String,String> map=WfUtilsEX.buildMap(entity,"yyyy年MM月dd日");
					map.put("taskid", "");
					maps.add(map);
				}
			}
		JSONArray jsonObject = JSONArray.fromObject(maps); 
		log.info("设施一览表"+jsonObject.toString());
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.getWriter().print(jsonObject.toString());
		return null;
	}
	/**
	 * 根据设施Id删除
	 * @return
	 * @throws Exception
	 */
	public String delSsylb()  throws Exception {
		String taskId=this.getRequest().getParameter("taskid");
		ywRqQyjyxkQxService.delSsylb(form.getSsylbid());
		
		ywRqQyjyxkQxService.delSsylbs(this.getId());
		this.getSsylbs(taskId);
		//this.ssylblist();
		return null;
	}
	
	/**
	 * 删除某几个设施
	 * @return
	 * @throws Exception
	 */
	public String delSomeSsylb() throws Exception{
		String checkids=BaseAction.getParameter("checkids");
		String taskId=this.getRequest().getParameter("taskid");
		String ids[]=checkids.split(",");
		System.out.println(ids.toString());
		for(int i=0;i<ids.length;i++){
			Long id=Long.parseLong(ids[i]);
			ywRqQyjyxkQxService.delSsylb(id);
		}
		this.getSsylbs(taskId);
		//this.ssylblist();
		return null;
	}
	
	public String getSsylb()  throws Exception {
		YwRqRqssylb entity=ywRqQyjyxkQxService.getSsylb(form.getSsylbid());
		if(entity!=null){
			if(entity.getBszsbh() == null){
	           ywRqQyjyxkQxService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
	           entity.setBszsbh(form.getBszsbh());
	            //form.setBszsbh(form.getZsbh() + "-000");
	       }else{
	    	   if(entity.getBszsbh().indexOf("null")>=0){
	    		   ywRqQyjyxkQxService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
		           entity.setBszsbh(form.getBszsbh());
				}
	       }
		   if(StringUtils.isBlank(entity.getFzorg())){
			   LoginUserForm uform=(LoginUserForm)this.getRequest().getSession().getAttribute("SES_LOGIN_USER");
			   entity.setFzorg(uform.getOrg().getOrgName());
		   }
		}
		JSONObject jsonObject = JSONObject.fromObject(entity);
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		String jsonString=jsonObject.toString();
		response.getWriter().print(jsonString);		
		
		return null;
	}
	/**
	 * 根据案件Id删除设施一览表信息
	 * @return
	 * @throws Exception
	 */
	public String delSsylbs()  throws Exception {
		String taskId=this.getRequest().getParameter("taskid");
		ywRqQyjyxkQxService.delSsylbs(this.getId());
		this.getSsylbs(taskId);
		//this.ssylblist();
		return null;
	}
	
	
	/**
	 * 根据案件Id查找设施一览表列表
	 * @return
	 * @throws Exception
	 */
	public String getSsylbs(String taskid)  throws Exception {
		List<YwRqRqssylb> list=ywRqQyjyxkQxService.findSsylbs(form.getId());
		List<Map> maps=new ArrayList<Map>();
			for(YwRqRqssylb entity:list){
				if(StringUtils.isNotBlank(taskid)){
					Map map=WfUtilsEX.buildMap(entity,"yyyy年MM月dd日");
					map.put("taskid", taskid);
					maps.add(map);
				}else{
					Map map=WfUtilsEX.buildMap(entity,"yyyy年MM月dd日");
					map.put("taskid", "");
					maps.add(map);
				}
			}
		JSONArray jsonObject = JSONArray.fromObject(maps); 
		log.info("设施一览表"+jsonObject.toString());
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.getWriter().print(jsonObject.toString());
		return null;
	}
	
	/**
	 * 导入设施一览表
	 * @return
	 * @throws Exception
	 */
	public String expExcel2Ssylb()  throws Exception {
        //保存设施一览表到数据库
		ywRqQyjyxkQxService.delSsylbs(form.getSsylbid());
        ywRqQyjyxkQxService.saveSsylbs(ywRqQyjyxkQxService.convertExcelToDB(form.getId()));
		this.ssylblist();
		return null;
	}
	/**
     * 窗口导入前检查
     * @return
     * @throws Exception
     */ 
    public String checkImportData() throws Exception{
        String qyid=getRequest().getParameter("qyid");
        String id=getRequest().getParameter("id");
        String templateCode=getRequest().getParameter("templateCode");

        String contextpath=getRequest().getSession().getServletContext().getRealPath("");
        //先查询收件材料是否存在
        boolean flag=ywRqQyjyxkQxService.checkData(templateCode,Long.valueOf(id),Long.valueOf(qyid));
        if(flag){
        	//检查人员是否在其他企业重复
        	String result=ywRqQyjyxkQxService.checkPerson(contextpath,templateCode,Long.valueOf(id),Long.valueOf(qyid));
        	//renderJson("{\"error\":"+result+"}");
        	getResponse().getWriter().print(result);
        	//            YwComQyxx qyxx=ywRqQyjyxkQxService.getYwComQyxx(Long.valueOf(qyid),acceptNo);
//            // YwComFinalQyxx finalQyxx=ywRqQyjyxkQxService.getYwComFinalQyxx(Long.valueOf(qyid));
//            if(qyxx!=null){
//                getResponse().getWriter().print("exist");
//            }
        }else{
        	//renderJson("{\"error\":dataNotExist}");
            getResponse().getWriter().print("dataNotExist");
        }
        
        return null;
    }
    /**
     * 查看正式企业信息前检查数据
     * @return
     * @throws Exception
     */
	public String checkViewData() throws Exception{
	    String qyid=getRequest().getParameter("qyid");
	    YwComFinalQyxx finalQyxx=ywRqQyjyxkQxService.getYwComFinalQyxx(Long.valueOf(qyid));
	    if(finalQyxx==null){
	       getResponse().getWriter().print("dataNotExist");
	    }
	    
	    return null;
	}
	
	   /**
     * 进入导入正式企业信息页面
     * @return
     * @author @zhangjun
     * @date 2011-10-16
     */
    public String showview(){
        getRequest().setAttribute("CurrUserName", this.getLoginUser().getUser().getUserName());
        if(form!=null){
            Long qyid=form.getQyid();
            YwRqQyjyxkFinalCyryzkdjb  finalcyryzk=null;
            YwRqQyjyxkCyryzkdjb cyryzk=null;
            YwRqQyjyxkFinalRqqxssdjb finalqxss=null;
            YwRqQyjyxkRqqxssdjb qxss=null;
            YwRqQyjyxkFinalPzrqgyzdjb finalrqqxssgyz=null;
            YwRqQyjyxkPzrqgyzdjb rqqxssgyz=null;
            YwRqQyjyxkRqssdjb rqssdjb=null;
            YwRqQyjyxkFinalRqssdjb finalRqssdjb=null;
            YwRqQyjyxkFinalRqjszdjb finalrqjszdjb=null;
            YwRqQyjyxkRqjszdjb rqjszdjb=null;
            
            //最终企业表
            YwComFinalQyxx finalEntity=this.ywRqQyjyxkQxService.getYwComFinalQyxx(qyid);
            //查询最终从业人员
            List<YwRqQyjyxkFinalCyryzkdjb> finalcyryzks=this.ywRqQyjyxkQxService.getFinalCyrys(qyid);
            //查询从业人员状况
            List<YwRqQyjyxkCyryzkdjb> cyryzks=this.ywRqQyjyxkQxService.getCyrys(qyid,form.getAcceptNo());
            if(finalcyryzks!=null &&finalcyryzks.size()>0){
                finalcyryzk=finalcyryzks.get(0);
            }
            if(cyryzks!=null &&cyryzks.size()>0){
                cyryzk=cyryzks.get(0);
            }
            //查询最终主要安全人员、技术管理
            List<YwRqQyjyxkFinalZyaqjsglryzk> finalzyaqjs=this.ywRqQyjyxkQxService.getFinalZyaqjs(qyid);
            //查询主要安全人员、技术管理
            List<YwRqQyjyxkZyaqjsglryzk> zyaqjs=this.ywRqQyjyxkQxService.getZyaqjs(qyid,form.getAcceptNo());
            //查询最终燃气抢险设备
            List<YwRqQyjyxkFinalRqqxsbylb> finalRqqxsbs=this.ywRqQyjyxkQxService.getFinalRqqxsbs(qyid);
            //查询燃气抢险设备
            List<YwRqQyjyxkRqqxsbylb> rqqxsbs=this.ywRqQyjyxkQxService.getRqqxsbs(qyid,form.getAcceptNo());
          //查询最终燃气抢险点
            List<YwRqQyjyxkFinalRqqxdylb> finalRqqxds=this.ywRqQyjyxkQxService.getFinalRqqxds(qyid);
            //查询燃气抢险点
            List<YwRqQyjyxkRqqxdylb> rqqxsqxds=this.ywRqQyjyxkQxService.getRqqxds(qyid,form.getAcceptNo());
            //查询最终燃气抢险设施
            List<YwRqQyjyxkFinalRqqxssdjb> finalRqqxss=this.ywRqQyjyxkQxService.getFinalRqqxss(qyid);
            //查询燃气抢险设施
            List<YwRqQyjyxkRqqxssdjb> rqqxss=this.ywRqQyjyxkQxService.getRqqxss(qyid,form.getAcceptNo());
           //最终燃气设施供应站
            List<YwRqQyjyxkFinalPzrqgyzdjb> finalrqqxssgyzs=this.ywRqQyjyxkQxService.getRqqxssGyz(qyid);
           //燃气设施供应站
            List<YwRqQyjyxkPzrqgyzdjb> rqqxssgyzs=this.ywRqQyjyxkQxService.getRqqxssGyz(qyid,form.getAcceptNo());
            //燃气设施登记表
            List<YwRqQyjyxkFinalRqssdjb> finalrqqxssdjs=this.ywRqQyjyxkQxService.getRqqxssfinalDjbs(qyid);
            List<YwRqQyjyxkRqssdjb> rqqxssdjs=this.ywRqQyjyxkQxService.getRqqxssDjbs(qyid,form.getAcceptNo());
            //瓶装燃气供应站人员配备情况
            List<YwRqQyjyxkFinalRypbqk>  finalpzrypbqks=ywRqQyjyxkQxService.getPzrybqks(qyid);
            List<YwRqQyjyxkRypbqk>  pzrypbqks=ywRqQyjyxkQxService.getPzrybqks(qyid,form.getAcceptNo());
            
            //燃气接收站、储配站、汽车加气站登记表
            List<YwRqQyjyxkFinalRqjszdjb> finalrqjszdjbs=this.ywRqQyjyxkQxService.getFinalRqjszdjb(qyid);
            List<YwRqQyjyxkRqjszdjb> rqjszdjbs=this.ywRqQyjyxkQxService.getRqjszdjb(qyid);
            //燃气接收站、储配站、汽车加气站主要设备
            List<YwRqQyjyxkRqjszzysb> rqjszzysbs=this.ywRqQyjyxkQxService.getzysbs(qyid,form.getAcceptNo());
            List<YwRqQyjyxkFinalRqjszzysb> finalrqjszzysbs=this.ywRqQyjyxkQxService.getfinalzysbs(qyid);
            
            //燃气接收站、储配站、汽车加气站人员配备情况
            List<YwRqQyjyxkRqjszrypbqk> finalrqjszrypbqks=this.ywRqQyjyxkQxService.getjszrypbqks(qyid,form.getAcceptNo());
            List<YwRqQyjyxkFinalRqjszrypbqk> rqjszrypbqks=this.ywRqQyjyxkQxService.getfinaljszrypbqks(qyid);
            
            //企业申报材料目录
            List<YwRqQyjyxkFinalQysbclmc> finalsbclmcs=this.ywRqQyjyxkQxService.getFinalQysbclmc(qyid);
            List<YwRqQyjyxkQysbclmc> sbclmcs=this.ywRqQyjyxkQxService.getQysbclmc(qyid,form.getAcceptNo());
            
            if(finalrqqxssgyzs!=null &&finalrqqxssgyzs.size()>0){
                finalrqqxssgyz=finalrqqxssgyzs.get(0);
            }
            if(rqqxssgyzs!=null &&rqqxssgyzs.size()>0){
                rqqxssgyz=rqqxssgyzs.get(0);//燃气设施供应站
            }
            
            if(finalRqqxss!=null &&finalRqqxss.size()>0){
                finalqxss=finalRqqxss.get(0);
            }
            if(rqqxss!=null &&rqqxss.size()>0){
                qxss=rqqxss.get(0);
            }
            if(rqqxssdjs!=null && rqqxssdjs.size()>0){
                rqssdjb=rqqxssdjs.get(0);
            }
            if(finalrqqxssdjs!=null && finalrqqxssdjs.size()>0){
                finalRqssdjb=finalrqqxssdjs.get(0);
            }
            if(finalrqjszdjbs!=null && finalrqjszdjbs.size()>0){
                finalrqjszdjb=finalrqjszdjbs.get(0);
            }
            if(rqjszdjbs!=null && rqjszdjbs.size()>0){
                rqjszdjb=rqjszdjbs.get(0);
            }
            getRequest().setAttribute("finalrqjszrypbqks", finalrqjszrypbqks);
            getRequest().setAttribute("rqjszrypbqks", rqjszrypbqks);
            
            getRequest().setAttribute("rqjszzysbs", rqjszzysbs);
            getRequest().setAttribute("finalzzysbs", rqjszzysbs);
            getRequest().setAttribute("finalrqjszzysbs", finalrqjszzysbs);
            getRequest().setAttribute("finalcyryzk", finalcyryzk);
            getRequest().setAttribute("finalrqqxssgyz", finalrqqxssgyz);
            getRequest().setAttribute("rqqxssgyz", rqqxssgyz);
            getRequest().setAttribute("cyryzk", cyryzk);
            getRequest().setAttribute("finalzyaqjs", finalzyaqjs);
            getRequest().setAttribute("zyaqjs", zyaqjs);
            getRequest().setAttribute("finalRqqxsbs", finalRqqxsbs);
            getRequest().setAttribute("rqqxsbs", rqqxsbs);
            getRequest().setAttribute("finalRqqxds", finalRqqxds);
            getRequest().setAttribute("rqqxsqxds", rqqxsqxds);
            getRequest().setAttribute("finalqxss", finalqxss);
            getRequest().setAttribute("qxss", qxss);
            getRequest().setAttribute("finalsbclmcs", finalsbclmcs);
            getRequest().setAttribute("sbclmcs", sbclmcs);
            getRequest().setAttribute("finalrqjszdjbs", finalrqjszdjbs);
            getRequest().setAttribute("rqjszdjbs", rqjszdjbs);
            getRequest().setAttribute("finalRqssdjb", finalRqssdjb);
            getRequest().setAttribute("rqssdjb", rqssdjb);
            getRequest().setAttribute("finalrqqxssdjs", finalrqqxssdjs);
            getRequest().setAttribute("rqqxssdjs", rqqxssdjs);
            
            getRequest().setAttribute("finalpzrypbqks", finalpzrypbqks);
            getRequest().setAttribute("pzrypbqks", pzrypbqks);
            getRequest().setAttribute("finalrqjszdjb", finalrqjszdjb);
            getRequest().setAttribute("finalrqqxssgyzs", finalrqqxssgyzs);
            getRequest().setAttribute("rqqxssgyzs", rqqxssgyzs);
            getRequest().setAttribute("finalEntity", finalEntity);
        }
        
        List<SysCodeForm> sqdwlx = syscodeService.getItems("YW_SQDW_LX");
        List<SysCodeForm> ywHbbm = syscodeService.getItems("ALL_HBBM");
        getRequest().setAttribute("sqdwlx", sqdwlx);
        getRequest().setAttribute("ywhbbm", ywHbbm);
        return "showview";
    }
	
    /**
     * 修改企业信息
     * @return
     * @throws Exception
     */
    public String doUpdate() throws Exception{
        Enumeration enu = getRequest().getParameterNames();
        String jsonStr="";
        while(enu.hasMoreElements()) {   
            String paraName = (String)enu.nextElement();   
            if(StringUtils.isNotBlank(paraName)){        
                jsonStr=paraName;
            }
        }  
        JSONObject jsonObject = JSONObject.fromObject(jsonStr); 
        String jyxkid=(String) jsonObject.get("jyxkid");
        String clsj=(String) jsonObject.get("clsj");//json对象转换时间问题
        YwRqQyjyxkForm entity=(YwRqQyjyxkForm) JSONObject.toBean(jsonObject, YwRqQyjyxkForm.class);
        
        if(StringUtils.isNotBlank(clsj)){
            Date clsjDate=DateUtilsEX.dateFormate(clsj, "yyyy年MM月dd日");
            entity.setClsj(clsjDate);
        }
        if(entity.getId()==null){
        	entity.setId(Long.valueOf(jyxkid));
        }
        try {
        	Long ids=form.getId();
            ywRqQyjyxkQxService.doUpdate(entity);
            getResponse().getWriter().print("success");
        } catch (Exception e) {
            log.error("修改失败"+e);
            getResponse().getWriter().print("fail");
        }
        
         return null;
   }
	
    /*
     * 入库的时候转换form 只转换经营许可的基本内容
     */
   private void changeForm(YwRqQyjyxkForm jyxk){
	   form.setSqdw(jyxk.getSqdw());
	   form.setAddress(jyxk.getAddress());
	   form.setClsj(jyxk.getClsj());
	   form.setYyzzzch(jyxk.getYyzzzch());
	   form.setLxr(jyxk.getLxr());
	   form.setLxdh(jyxk.getLxdh());
	   form.setDzyx(jyxk.getDzyx());
	   form.setCz(jyxk.getCz());
	   form.setQywz(jyxk.getQywz());
	   form.setFddbr(jyxk.getFddbr());
	   form.setFddbrZw(jyxk.getFddbrZw());
	   form.setFddbrZc(jyxk.getFddbrZc());
	   form.setZyfzr(jyxk.getZyfzr());
	   form.setZyfzrZc(jyxk.getZyfzrZc());
	   form.setZyfzrZw(jyxk.getZyfzrZw());
	   form.setJsfzr(jyxk.getJsfzr());
	   form.setJsfzrZc(jyxk.getJsfzrZc());
	   form.setJsfzrZw(jyxk.getJsfzrZw());
	   form.setZczj(jyxk.getZczj());
	   form.setQylx(jyxk.getQylx());
	   form.setJyfw(jyxk.getJyfw());
	   form.setGqqy(jyxk.getGqqy());
	   form.setFwdh(jyxk.getFwdh());
	   form.setQxdh(jyxk.getQxdh());
	   form.setQyjj(jyxk.getQyjj());
	 
   }
   
    
    
    /**
     * 窗口收案环节导入数据
     */
    public String  importFinalData() throws Exception{
        Map map=getMapByRequest(getRequest());
        String contextPath=getRequest().getSession().getServletContext().getRealPath("");
        map.put("contextPath", contextPath);
        String result=ywRqQyjyxkQxService.importFinalData(form,map);
        getResponse().getWriter().print(result);
        return null;
    }
	
    /**
     *获取返回后导入的数据
     * @return
     * @throws IOException 
     */
    public String getResultImportData () throws IOException{
       if(form!=null && form.getId()!=null){
           JSONObject jsonObject = JSONObject.fromObject(form); 
           getResponse().getWriter().print(jsonObject.toString());
       }
        return null;
    }
    
    /**
     * 到办结环节导入
     * @return
     */
    public String importFinalQyData(){
        Map map=getMapByRequest(getRequest());
        //导入企业正式信息
        String sqdw=form.getSqdw();
        map.put("sqdw", sqdw);
        Map msgMap=ywRqQyjyxkQxService.importFinalQyData(form,map);
        return null;
    }
    
    
    
    //获取request对象中所有参数，并设置到map中
    private  Map getMapByRequest(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration enu = request.getParameterNames();
        while(enu.hasMoreElements()) {   
            String paraName = (String)enu.nextElement();   
            String paraValue = request.getParameter(paraName).trim(); 
            if(paraValue!=null && !"".equals(paraValue)){
                map.put(paraName, paraValue);
            }           
        }
                
        return map;
    }   
	public YwRqQyjyxkForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<YwRqQyjyxkForm> getPage() {
		return page;
	}


	public void setPage(Page<YwRqQyjyxkForm> page) {
		this.page = page;
	}
	
	public String printcz() throws Exception {
		form.setCbyw(form.getCbyw().replace("区县", "").replace("区", ""));
		String taskId=getRequest().getParameter("taskInstDbid");
		String activName="";
		if(StringUtils.isNotBlank(taskId)){
		  	WfBusInstanceTaskForm instance = wfService.getWfBusInstanceTaskById(Long.valueOf(taskId), this.getLoginUserName());
		  	if(instance != null){
				 activName=instance.getActivityName();
				if(StringUtils.isNotBlank(activName)){
					getRequest().setAttribute("activName", activName);
				}else{
					getRequest().setAttribute("activName", "");
				}		
			}
		}else{
			 getRequest().setAttribute("activName", "");
		}
		this.setValue(form);
		if(form.getId() != null && form.getId() > 0){
			WfBusTemplateForm wfBusTemplateForm = wfBusTemplateService.getByTemplateCode(getTemplateCode());
            if (wfBusTemplateForm != null) {
                form.setCbyw(wfBusTemplateForm.getTemplateName().replace("区县", "").replace("区", ""));
            }
			form.setCbyw2(form.getCbyw());
			form.setCbyw3(form.getCbyw());
			form.setCbyw4(form.getCbyw());
    		List<YwPrintDocForm> ywPrintDocFormList = ywPrintDocService.get(form.getTemplateCode(), form.getFileCode(), form.getId());
        	if(ywPrintDocFormList!=null && ywPrintDocFormList.size()>0){
    			return WfConstant.PRINT_DIR;
    		}
    	}
        return WfUtilsEX.wfBusPrint(form, form.getId(), activName);
    }
	
	
	/**
	 * 主要用于制文的安全考核表
	 * @param form
	 */
	private void setValue(YwRqQyjyxkForm form){
		Field[] field = form.getClass().getDeclaredFields();    
        for(int j=0 ; j<field.length ; j++){     
            try {
				String fieldName = field[j].getName();  
				String type = field[j].getGenericType().toString();   
				if(fieldName.length()>4){
					if(fieldName.substring(0,4).equals("khjg")){
    				    Method m = form.getClass().getMethod("get"+StringUtils.capitalize(fieldName));
    				    String value = (String) m.invoke(form);   
    				    if("1".equals(value)){
    				        ReflectionUtils.setFieldValue(form, fieldName, "合格");
    				    }else if("0".equals(value)){
    				    	 ReflectionUtils.setFieldValue(form, fieldName, "不合格");
    				    }
					}
				}
				if(fieldName.length()>6){
				 if(fieldName.substring(0,6).equals("sqkhjg")){
					    Method m = form.getClass().getMethod("get"+StringUtils.capitalize(fieldName));
	    				    String value = (String) m.invoke(form);   
	    				    if("1".equals(value)){
	    				        ReflectionUtils.setFieldValue(form, fieldName, "合格");
	    				    }else if("0".equals(value)){
	    				    	 ReflectionUtils.setFieldValue(form, fieldName, "不合格");
	    				    }
					}
				}
			} catch (Exception e) {
				log.error("转换异常"+e);
			}
        }
	}
	//制作补交受理通知书的时候，先检查是否填写了补交受理表的补交材料
	public void checkedBjclqd() throws Exception {
		System.out.println("form.getBjclqd() +++++++++= "+form.getBjclqd());
		if(StringUtils.isBlank(form.getBjclqd())){
			getResponse().getWriter().print("请先填写并保存补交受理材料清单！");
    	}else{
    		getResponse().getWriter().print("success");
    	}
	}
}
